package com.example.spring5.ms;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: Hu Rui
 * @Date: 2021/11/11 20:57
 */
public class ThreadPrintDemo {
    static AtomicInteger cxsNum = new AtomicInteger(1);

    public static void main(String[] args) {

        Thread t1 = new Thread(() -> {
            while (cxsNum.get() < 100) {
                if (cxsNum.get() % 2 == 1) {
                    System.out.println("t1:" + cxsNum.get());
                    cxsNum.incrementAndGet();
                }
            }
        });

        Thread t2 = new Thread(() -> {
            while (cxsNum.get() <= 100) {
                if (cxsNum.get() % 2 == 0) {
                    System.out.println("t2:" + cxsNum.get());
                    cxsNum.incrementAndGet();
                }
            }
        });

        t1.start();
        t2.start();
    }
}
